<template>
  <div>
    <el-dialog
      v-model="editVisible"
      width="50%"
      top="10%"
      @close="handleclose"
      :close-on-click-modal="false"
    >
      <el-form label-width="120px">
        <el-form-item label="开关：" :required="true">
          <el-select
            placeholder="请选择"
            class="width_accout"
            v-model="add_from.acState"
          >
            <el-option
              v-for="item in switchList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              @change="handleSwitch"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="运转模式：" :required="true">
          <el-select
            placeholder="请选择"
            class="width_accout"
            v-model="add_from.runMode"
          >
            <el-option
              v-for="item in pattern"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="温度：" :required="true">
          <el-select
            placeholder="请选择"
            class="width_accout"
            v-model="add_from.setTemp"
          >
            <el-option
              v-for="item in CtlTemperature"
              :key="item.paramName"
              :label="item.paramName"
              :value="item.paramName"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="风速：" :required="true">
          <el-select
            placeholder="请选择"
            class="width_accout"
            v-model="add_from.windSpeed"
          >
            <el-option
              v-for="item in windSpeed"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="风向：" :required="true">
          <el-select
            placeholder="请选择"
            class="width_accout"
            v-model="add_from.windDirect"
          >
            <el-option
              v-for="item in windDirect"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="editVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleclick">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script>
import { ElMessage, ElMessageBox } from "element-plus";
import { ref, reactive } from "vue";
import { dictionaries } from "../assets/js/dictionaries";
export default {
  components: {},
  setup(props, context) {
    console.log(context);
    // 参考图片
    const editVisible = ref(context.attrs.editVisible);
    const add_from = reactive(context.attrs.add_from);
    console.log(context.attrs.airList);
    const handleclose = () => {
      editVisible.value = false;
      context.emit("handleclose", editVisible.value);
    };
    // 分控温度
    const CtlTemperature = ref([]);
    dictionaries("infraredTemperature").then((res) => {
      CtlTemperature.value = res;
    });
    const handleclick = () => {
      console.log(add_from);
      if (add_from.acState == null) {
        ElMessage.error("请选择开关");
        return;
      } else if (add_from.runMode == null) {
        ElMessage.error("请选择运转模式");
        return;
      } else if (add_from.setTemp == null) {
        ElMessage.error("请选择温度");
        return;
      } else if (add_from.windSpeed == null) {
        ElMessage.error("请选择风速");
        return;
      } else if (add_from.windDirect == null) {
        ElMessage.error("请选择风向");
        return;
      }
      context.emit("handleclick", add_from, editVisible.value);
    };
    const handleSwitch = () => {
      add_from.windSpeed = 0;
      add_from.windDirect = 0;
    };
    return {
      editVisible,
      add_from,
      CtlTemperature,
      switchList: [
        {
          value: 1,
          label: "开启",
        },
        {
          value: 0,
          label: "关闭",
        },
      ],
      pattern: [
        {
          value: 0,
          label: "自动",
        },
        {
          value: 1,
          label: "制冷",
        },
        {
          value: 2,
          label: "除湿",
        },
        {
          value: 3,
          label: "送风",
        },
        {
          value: 4,
          label: "制热",
        },
      ],
      windSpeed: [
        {
          value: 0,
          label: "自动",
        },
        {
          value: 1,
          label: "风速1",
        },
        {
          value: 2,
          label: "风速2",
        },
        {
          value: 3,
          label: "风速3",
        },
      ],
      windDirect: [
        {
          value: 0,
          label: "自动",
        },
        {
          value: 1,
          label: "风向1",
        },
        {
          value: 2,
          label: "风向2",
        },
        {
          value: 3,
          label: "风向3",
        },
        {
          value: 4,
          label: "风向4",
        },
      ],
      handleclick,
      handleclose,
      handleSwitch,
    };
  },
};
</script>
<style lang="less" scoped>
&:deep(.el-dialog) {
  background: #fff;
}
// &:deep(.el-overlay){
//   z-index:999 !important;
// }
</style>
